<template>
  <el-container class="layout" :class="{ 'dark-mode': isDarkMode }">
    <el-aside :width="isCollapsed ? '64px' : '330px'">
      <el-menu
        :collapse="isCollapsed"
        :collapse-transition="false"
        background-color="#304156"
        text-color="#bfcbd9"
        active-text-color="#409EFF"
      >
        <!-- 菜单项 -->
        <el-menu-item index="1">
          <el-icon><House /></el-icon>
          <template #title>首页</template>
        </el-menu-item>
        <!-- 更多菜单项 -->
      </el-menu>
    </el-aside>
    
    <el-container>
      <el-header>
        <div class="header-content">
          <el-button
            type="text"
            @click="toggleCollapse"
            :icon="isCollapsed ? 'Expand' : 'Fold'"
          />
          
          <div class="header-right">
            <el-dropdown>
              <span class="el-dropdown-link">
                <el-avatar :size="32" :src="user.avatar" />
                <span>{{ user.name }}</span>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>个人中心</el-dropdown-item>
                  <el-dropdown-item>退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
            
            <el-button type="text" @click="refreshPage" :icon="Refresh" />
            <el-button
              type="text"
              @click="toggleDarkMode"
              :icon="isDarkMode ? 'Sunny' : 'Moon'"
            />
          </div>
        </div>
      </el-header>
      
      <el-main>
        <slot />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import {
  House,
  Expand,
  Fold,
  Refresh,
  Sunny,
  Moon
} from '@element-plus/icons-vue'

const isCollapsed = ref(false)
const isDarkMode = ref(false)
const user = ref({
  name: '用户名',
  avatar: 'https://example.com/avatar.png'
})

const toggleCollapse = () => {
  isCollapsed.value = !isCollapsed.value
}

const toggleDarkMode = () => {
  isDarkMode.value = !isDarkMode.value
  document.documentElement.classList.toggle('dark', isDarkMode.value)
}

const refreshPage = () => {
  window.location.reload()
}
</script>

<style scoped>
.layout {
  height: 100vh;
}

.el-aside {
  background-color: #304156;
  transition: width 0.3s;
}

.el-header {
  padding: 0;
  background-color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.el-dropdown-link {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.dark-mode {
  --el-bg-color: #1a1a1a;
  --el-text-color-primary: #ffffff;
}

.dark-mode .el-header {
  background-color: #2d2d2d;
}
</style>
